import { Lifecycle, scoped } from "tsyringe";
import { clickButton, getCurrentViewNode } from "../utils";
@scoped(Lifecycle.ContainerScoped)
export class Router {
    private stack: string[];

    constructor() {
        this.stack = [];
    }

    push(route: string): void {
        this.stack.push(route);
    }

    pop(): string | undefined {
        return this.stack.pop();
    }

    peek(): string | undefined {
        return this.stack[this.stack.length - 1];
    }

    isEmpty(): boolean {
        return this.stack.length === 0;
    }

    clear(): void {
        this.stack = [];
    }

    size(): number {
        return this.stack.length;
    }

    back() {
        if (!!this.pop()) {
            if (back()) {
                return true;
            } else {
                log(`回退失败`)
            }
        }
    }

    home() {
        while (this.pop()) {
            if (back()) {
                this.hook && this.hook()
            } else {
                log(`回退失败`)
            }
        }
    }
    hook: Function;
    setHook(hook: Function) {
        this.hook = hook;
    }
}
